//
//  WBNavigationViewController.swift
//  desunireWeibo
//
//  Created by desunire on 2017/8/24.
//  Copyright © 2017年 desunire. All rights reserved.
//

import UIKit

class WBNavigationViewController: UINavigationController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        //隐藏navBar，自定义一个bar
        navigationBar.isHidden = true
    }

//push的层数0-1  重写push方法
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        
        print(viewController)
        //如果不是栈底控制器
        if childViewControllers.count > 0 {
            //隐藏底部的TabBar
            viewController.hidesBottomBarWhenPushed = true
            var title = "返回"
            //只有一个子控制器的标题
            if childViewControllers.count == 1 {
                 //title = navigationItem.title ?? "返回"
                title=childViewControllers.first?.title ?? "返回"
            }
            //设置左侧按钮作为返回按钮
            //判断控制器类型
            if let vc = viewController as? WBBaseViewController {
                //取出navItem
                vc.navItem.leftBarButtonItem = UIBarButtonItem.init(title: title, fontSize: 16.0, target: self, action: #selector(goBack), isBack: true)
            }
            
        }
        super.pushViewController(viewController, animated: true)
        
    }
    
    
    @objc fileprivate func goBack(){
        popViewController(animated: true)
    }
    

}
